package main

import (
	"github.com/zeromicro/go-zero/core/logx"
)

// 实现service.Service接口
func (s *WebSocketServer) Start() {
	logx.Info("WebSocket服务已启动")
}

// 实现service.Service接口
func (s *WebSocketServer) Stop() {
	logx.Info("WebSocket服务正在关闭...")

	// 关闭所有房间和客户端连接
	s.mu.Lock()
	defer s.mu.Unlock()

	for _, room := range s.Rooms {
		room.mu.Lock()
		for _, client := range room.Clients {
			close(client.Send)
			client.Conn.Close()
		}
		room.Clients = make(map[string]*Client)
		room.mu.Unlock()
	}

	s.Rooms = make(map[string]*Room)
	logx.Info("WebSocket服务已关闭")
}
